#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :删除多余的图片.py
# @Time      :2024/3/20 
# @Author    :CL
# @email     :1037654919@qq.com

import os
path = f'/media/chenglei3/77D014CED257D1411/images/huaban/'
keyword_ens = os.listdir(path)
print(keyword_ens)
for  keyword_en in keyword_ens:
    path = f'/media/chenglei3/77D014CED257D1411/images/huaban/{keyword_en}/'
    # 获取文件列表
    file_list = os.listdir(path)
    print(keyword_en,len(file_list))
    # 如果文件数量超过10000个，则进行删除操作
    if len(file_list) > 2500:
        for i in range(2500, len(file_list)):
            file_to_delete = os.path.join(path, file_list[i])
            os.remove(file_to_delete)
